InputText = function(scene) {
	
	this.scene = scene;
	this.isFocused = true;
	this.boxWidth = 400;
	this.boxHeight = 70;
	this.boxDepth = 70;

	this.textColor = 0xffffff;
	this.textMaterial = new THREE.MeshBasicMaterial( { color: this.textColor, overdraw: true } );
	this.letterSize = 50;
	this.letterDepth = 3;
	this.textFont = 'helvetiker';
	this.textWeight = 'normal';
	this.textStyle = 'normal';
	this.letters = [];

	this.boxColor = 0xff0000;
	this.boxOpacity = 0.7;
	this.boxGeometry = new THREE.CubeGeometry( this.boxWidth, this.boxHeight, this.boxDepth );
	this.boxMesh = new THREE.Mesh( this.boxGeometry, new THREE.MeshBasicMaterial( { color: this.boxColor, opacity: this.boxOpacity, transparent: true } ) );

	//test
	this.boxMesh.rotation.x = (45/180)*3.14;
	this.boxMesh.rotation.y = (45/180)*3.14;
	//END test

	this.scene.add(this.boxMesh);

	this.OnKeyDown = function (event) {
		if(this.isFocused) {
			var evt = event || window.event;
			var keycode = 0;
			if (evt) keycode = evt.which || evt.keyCode;

			var prevLetter = this.letters[this.letters.length-1];

			if(keycode == 8) {
				if(prevLetter) {
					this.letters.splice(this.letters.indexOf(prevLetter), 1);
					this.boxMesh.remove(prevLetter.mesh);
				}
				evt.preventDefault();
			}
		}
	}
	this.OnKeyPress = function (event) {
		if(this.isFocused) {

			var evt = event || window.event;
			var keycode = 0;
			if (evt) keycode = evt.which || evt.keyCode;

			var prevLetter = this.letters[this.letters.length-1];

			if(keycode >= 9 && keycode <= 46 && keycode != 32){

			} else {
				var charFromCode = String.fromCharCode(keycode);
				var textMesh = new THREE.Mesh(new THREE.TextGeometry( charFromCode, {size: this.letterSize, height: this.letterDepth, curveSegments: 1, font: this.textFont, weight: this.textWeight, style: this.textStyle } ), this.textMaterial);
				
				var letterXpos = -this.boxWidth/2 + 10;
				if(prevLetter) {
					letterXpos = prevLetter.mesh.position.x + this.letterSize + 10;
				}

				textMesh.position.x = letterXpos;
				textMesh.position.y = -this.boxHeight/2 + 15;

				this.boxMesh.add(textMesh);

				this.letters.push(new InputLetter(charFromCode, textMesh));
			}
			
		}
	}
	
	this.getValue = function() {
		var result = '';
		for(var i = 0; i < this.letters.length; i++) {
			result += this.letters[i].letter;
		}
		return result;
	}

	document.addEventListener( 'keydown', bindFn( this, this.OnKeyDown ), false );
	document.addEventListener( 'keypress', bindFn( this, this.OnKeyPress ), false );

	
}

InputLetter = function(letter, mesh) {
	this.mesh = mesh;
	this.letter = letter;
}